//
//  TransportVC.m
//  saler-ios
//
//  Created by 王亚陆 on 17/5/31.
//  Copyright © 2017年 sayimba. All rights reserved.
//

#import "TransportVC.h"
#import "BegainAddressVC.h"
#import "EndAddressVC.h"
#import "ActionSheetPicker.h"
#import "ChooseCarVC.h"
#import "AddCarCell.h"
#import "ConfirmVC.h"
#import "FreightVC.h"
#import <UIImageView+WebCache.h>
#import "HomeVC.h"
#import "CarInforModel.h"
#import "AddCarVinsVC.h"
#import "InvoiceVC.h"
#import "HandCarVC.h"
#import "PickCarVC.h"
#import "BegainAddressChooseVC.h"
#import "EndAddressChooseVC.h"
#define SmallTag 3000
#define BigTag 4000



@interface TransportVC ()
<
UITableViewDataSource,
UITableViewDelegate,
UIScrollViewDelegate,
UITextViewDelegate>
{
    UIImageView * nav;
    Common * com;
    RootViewController * TabBar;
    UILabel * begainAddressLabel;
    UILabel * endAddressLabel;
    UILabel * chooseTimeLabel;
    UILabel * chooseHandTimeLabel;
    UILabel * chooseBillLabel;

    UILabel * addCarInforLabel;
    NSMutableArray * addCarInforArr;

    int NUmber;
    NSString * begainID;
    NSString * endID;
    NSMutableDictionary * postDic;
    UIImageView * InforImage;
    CarInforModel * carModel;
    UIImageView * TimeImage;
    UILabel * totalCarNumber;
    UIImageView * totalImage;
}

@property (nonatomic,strong) UIScrollView * ScrollView;
@property (nonatomic,strong) UITableView * TableView;
@property (nonatomic,strong) WKProgressHUD *hud;

@property (nonatomic,strong) UIView * backview1;
@property (nonatomic,strong) UIView * backview2;


@end

@implementation TransportVC

/**
 初始化PostDic字典
 */
- (void)resetPostDic {
    
    [postDic setObject:@"" forKey:@"destRegionName"];
    [postDic setObject:@"" forKey:@"destPhone"];
    
    [postDic setObject:@"" forKey:@"destContact"];
    [postDic setObject:@"" forKey:@"destPhone"];
    
    
    //提车信息
    [postDic setObject:@"" forKey:@"departContact"];
    [postDic setObject:@"" forKey:@"departPhone"];
    [postDic setObject:@"" forKey:@"departAddr"];
    [postDic setObject:@"" forKey:@"isPick"];
    [postDic setObject:@"" forKey:@"pickDate"];
    [postDic setObject:@"" forKey:@"pickTime"];
    
    
    
    //交车信息
    [postDic setObject:@"" forKey:@"destContact"];
    [postDic setObject:@"" forKey:@"destPhone"];
    [postDic setObject:@"" forKey:@"destAddr"];
    [postDic setObject:@"" forKey:@"isDeliv"];
    
    
    //发票
    [postDic setObject:@"" forKey:@"isTicket"];
    [postDic setObject:@"" forKey:@"companyName"];
    [postDic setObject:@"" forKey:@"identifyNumber"];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    nav = [self createNav:@"物流运输"];
    [self.view addSubview:nav];
    self.view.backgroundColor = UIviewBackColor;
    
    addCarInforArr = [[NSMutableArray alloc]init];
    postDic = [[NSMutableDictionary alloc]init];
    carModel = [[CarInforModel alloc]init];
    

    [self resetPostDic];
    
    
    NUmber = 0;
    [self createUI];
    
    //查询物价 跳转-下单-返回首页
    if (self.backHome) {
        
        UIButton * btn = [UIButton createUIbutton:@"" andFont:FontOfSize12 andColor:nil];
        [nav addSubview:btn];
        [btn addTarget:self action:@selector(pressBackHome) forControlEvents:UIControlEventTouchUpInside];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(nav.mas_left);
            make.centerY.mas_equalTo(nav.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(100*kWidth, 50*kHeight));
        }];
    }
}


#pragma mark - 跳回首页
-(void)pressBackHome{
    
    for (UIViewController *controller in self.navigationController.viewControllers) {
        if ([controller isKindOfClass:[HomeVC class]]) {
            [self.navigationController popToViewController:controller animated:YES];
        }
    }
}

#pragma mark - 创建视图
-(void)createUI{
    
    [self createScroll];
    [self createBackview1];
    [self createBackview2];
    [self createBtn];
    
}

#pragma mark - 创建滚动视图
-(void)createScroll{
    
    _ScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 74*kHeight, Main_Width,Main_height)];
    _ScrollView.contentOffset = CGPointMake(0, 0);
    _ScrollView.contentSize = CGSizeMake(Main_Width, Main_height+300*kHeight);
    _ScrollView.backgroundColor = UIviewBackColor;
    self.automaticallyAdjustsScrollViewInsets =NO;
    _ScrollView.bounces = NO;
    _ScrollView.userInteractionEnabled = YES;
    _ScrollView.showsHorizontalScrollIndicator = NO;
    _ScrollView.showsVerticalScrollIndicator = NO;
    _ScrollView.delegate = self;
    [self.view addSubview:_ScrollView];
}

#pragma mark - 创建背景图 一
-(void)createBackview1{
    
    
    _backview1 = [[UIView alloc]init];
    _backview1.backgroundColor = WhiteColor;
    [_ScrollView addSubview:_backview1];
    [_backview1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_ScrollView.mas_centerX);
        make.top.mas_equalTo(_ScrollView.mas_top);
        make.size.mas_equalTo(CGSizeMake(view_Width, 550*kHeight));
    }];
    
    UIImageView * addressImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_address"]];
    [_backview1 addSubview:addressImage];
    [addressImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left).with.offset(24*kWidth);
        make.top.mas_equalTo(_backview1.mas_top).with.offset(25*kHeight);
        make.size.mas_equalTo(CGSizeMake(10*kWidth, 15*kHeight));
    }];
    
    
    //运输地址
    UILabel * addressLabel = [UILabel createUIlabel:@"运输地址" andFont:14 andColor:UIlabelColor];
    [_backview1 addSubview:addressLabel];
    [addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressImage.mas_right).with.offset(22*kWidth);
        make.centerY.mas_equalTo(addressImage.mas_centerY);
    }];
    
    UIImageView * begainAddressImage = [[UIImageView alloc]init];
    begainAddressImage.image = [UIImage imageNamed:@"home_yellow"];
    [_backview1 addSubview:begainAddressImage];
    [begainAddressImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left).with.offset(22*kWidth);
        make.top.mas_equalTo(addressImage.mas_bottom).with.offset(45*kHeight);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 6*kHeight));
    }];
    
    begainAddressLabel = [UILabel createUIlabel:@"始发地" andFont:14 andColor:UIbtnColor];
    [_backview1 addSubview:begainAddressLabel];
    [begainAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(begainAddressImage.mas_centerY);
    }];
    
    
    UIImageView * chooseImage1 = [[UIImageView alloc]init];
    chooseImage1.image = [UIImage imageNamed:@"personal_arrow"];
    [_backview1 addSubview:chooseImage1];
    [chooseImage1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-10*kWidth);
        make.centerY.mas_equalTo(begainAddressLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 11*kHeight));
    }];

    

    
    UIButton * begainBtn = [UIButton createUIbutton:@"" andFont:1 andColor:nil];
    [begainBtn addTarget:self action:@selector(pressBegainBtn) forControlEvents:UIControlEventTouchUpInside];
    [_backview1 addSubview:begainBtn];
    [begainBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(begainAddressImage.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(Main_Width-20*kWidth, 40*kHeight));
    }];

    
    UIView * lineView1= [[UIView alloc]init];
    lineView1.backgroundColor = LineColor;
    [_backview1 addSubview:lineView1];
    [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(begainAddressLabel.mas_left);
        make.right.mas_equalTo(_backview1.mas_right);
        make.centerY.mas_equalTo(begainAddressLabel.mas_centerY).with.offset(15*kHeight);
        make.height.mas_equalTo(0.5*kHeight);
    }];
    
    //交换 起始地和目的地
    /*
    UIImageView * changeImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"home_change"]];
    [_backview1 addSubview:changeImage];
    [changeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-25*kWidth);
        make.top.mas_equalTo(_backview1.mas_top).with.offset(102*kHeight);
        make.size.mas_equalTo(CGSizeMake(15*kWidth, 20*kHeight));
    }];

    UIButton * chooserBtn = [UIButton createUIbutton:@"" andFont:1 andColor:nil];
    [chooserBtn addTarget:self action:@selector(pressChooseBtn) forControlEvents:UIControlEventTouchUpInside];
    [_backview1 addSubview:chooserBtn];
    [chooserBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-25*kWidth);
        make.centerY.mas_equalTo(changeImage.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(50*kWidth, 40*kHeight));
    }];
     */


    UIImageView * endAddressImage = [[UIImageView alloc]init];
    endAddressImage.image = [UIImage imageNamed:@"home_blue"];
    [_backview1 addSubview:endAddressImage];
    [endAddressImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left).with.offset(24*kWidth);
        make.top.mas_equalTo(begainAddressImage.mas_bottom).with.offset(55*kHeight);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 6*kHeight));
    }];
    
    endAddressLabel = [UILabel createUIlabel:@"目的地" andFont:14 andColor:UIbtnColor];
    [_backview1 addSubview:endAddressLabel];
    [endAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(endAddressImage.mas_centerY);
    }];
    
    
    
    
    UIImageView * chooseImage2 = [[UIImageView alloc]init];
    chooseImage2.image = [UIImage imageNamed:@"personal_arrow"];
    [_backview1 addSubview:chooseImage2];
    [chooseImage2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-10*kWidth);
        make.centerY.mas_equalTo(endAddressLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 11*kHeight));
    }];

    
    
    UIButton * endBtn = [UIButton createUIbutton:@"" andFont:1 andColor:nil];
    [endBtn addTarget:self action:@selector(pressEndBtn) forControlEvents:UIControlEventTouchUpInside];
    [_backview1 addSubview:endBtn];
    [endBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(endAddressLabel.mas_left);
        make.centerY.mas_equalTo(endAddressImage.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(Main_Width-20*kWidth, 40*kHeight));
    }];

    UIView * lineView2= [[UIView alloc]init];
    lineView2.backgroundColor = LineColor;
    [_backview1 addSubview:lineView2];
    [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(endAddressLabel.mas_left);
        make.right.mas_equalTo(_backview1.mas_right);
        make.centerY.mas_equalTo(endAddressLabel.mas_centerY).with.offset(15*kHeight);
        make.height.mas_equalTo(0.5*kHeight);
    }];

    

    
    
    //商品车信息
    UIImageView * CarInforImage = [[UIImageView alloc]init];
    CarInforImage.image = [UIImage imageNamed:@"home_infor"];
    [_backview1 addSubview:CarInforImage];
    [CarInforImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left).with.offset(24*kWidth);
        make.centerY.mas_equalTo(lineView2.mas_bottom).with.offset(30*kHeight);
        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
    }];

    UILabel * carInforLabel = [UILabel createUIlabel:@"商品车信息" andFont:14 andColor:UIlabelColor];
    [_backview1 addSubview:carInforLabel];
    [carInforLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(CarInforImage.mas_centerY);
    }];
    
    
    InforImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Add-to"]];
    InforImage.hidden = YES;
    [_backview1 addSubview:InforImage];
    [InforImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-26*kWidth);
        make.centerY.mas_equalTo(carInforLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(18*kWidth, 18*kHeight));
    }];
    
    UIButton * AddToBtn = [UIButton createUIbutton:@"" andFont:1 andColor:nil];
    [AddToBtn addTarget:self action:@selector(pressAddCarBtn) forControlEvents:UIControlEventTouchUpInside];
    AddToBtn.tag = 10000;
    AddToBtn.userInteractionEnabled = NO;
    [_backview1 addSubview: AddToBtn];
    [AddToBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-10*kWidth);
        make.centerY.mas_equalTo(carInforLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(50*kWidth, 40*kHeight));
    }];

    //初始化 显示
    addCarInforLabel = [UILabel createUIlabel:@"添加商品车信息" andFont:14 andColor:UIbtnColor];
    [_backview1 addSubview:addCarInforLabel];
    [addCarInforLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(carInforLabel.mas_centerY).with.offset(30*kHeight);
    }];
    
    
    
    UIImageView * chooseImage4 = [[UIImageView alloc]init];
    chooseImage4.image = [UIImage imageNamed:@"personal_arrow"];
    chooseImage4.tag = 100;

    [_backview1 addSubview:chooseImage4];
    [chooseImage4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-10*kWidth);
        make.centerY.mas_equalTo(addCarInforLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 11*kHeight));
    }];

    
    
    
    
    
    UIView * lineView4= [[UIView alloc]init];
    lineView4.backgroundColor = LineColor;
    lineView4.tag = 200;
    [_backview1 addSubview:lineView4];
    [lineView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addCarInforLabel.mas_left);
        make.centerY.mas_equalTo(addCarInforLabel.mas_centerY).with.offset(15*kHeight);
        make.height.mas_equalTo(0.5*kHeight);
        make.right.mas_equalTo(_backview1.mas_right);
    }];
    
    
    UIButton * addCarBtn= [UIButton createUIbutton:@"" andFont:1 andColor:nil];
    [addCarBtn addTarget:self action:@selector(pressAddCarBtn) forControlEvents:UIControlEventTouchUpInside];
    [_backview1 addSubview:addCarBtn];
    [addCarBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addCarInforLabel.mas_left);
        make.centerY.mas_equalTo(addCarInforLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(Main_Width-20*kWidth, 40*kHeight));
    }];
    
    
    //商品车信息 初始化 隐藏
    _TableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Main_Width, 43*0*kHeight) style:UITableViewStylePlain];
    _TableView.hidden = NO;
    [_TableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    _TableView.delegate = self;
    _TableView.dataSource = self;
    _TableView.userInteractionEnabled = YES;
    _TableView.scrollEnabled = NO;
    [_backview1 addSubview:_TableView];
    [_TableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left).with.offset(0);
        make.top.mas_equalTo(carInforLabel.mas_bottom).with.offset(5*kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width-20*kWidth, 43*0.001*kHeight));
    }];
    
    
    //合计
    totalImage = [[UIImageView alloc]init];
    totalImage.userInteractionEnabled = YES;
    totalImage.hidden = YES;
    [_backview1 addSubview:totalImage];
    [totalImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left).with.offset(0);
        make.top.mas_equalTo(_TableView.mas_bottom).with.offset(5*kHeight);
        make.size.mas_equalTo(CGSizeMake(Main_Width-20*kWidth, 43*kHeight));
    }];
    
    UILabel * totalLabel = [UILabel  createUIlabel:@"合计" andFont:FontOfSize13 andColor:AddCarColor];
    [totalImage addSubview:totalLabel];
    
    [totalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(totalImage.mas_left).with.offset(56*kWidth);
        make.centerY.mas_equalTo(totalImage.mas_centerY);
    }];
    


    totalCarNumber = [UILabel createUIlabel:@"1台" andFont:FontOfSize13 andColor:AddCarColor];
    [totalImage addSubview:totalCarNumber];
    [totalCarNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(totalImage.mas_centerX).with.offset(-30*kWidth);
        make.centerY.mas_equalTo(totalImage.mas_centerY);
    }];
    
    UILabel * carVin = [UILabel createUIlabel:@"录入车架号" andFont:FontOfSize13 andColor:RedColor];

    [totalImage addSubview:carVin];
    [carVin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(totalImage.mas_right).with.offset(-30*kWidth);
        make.centerY.mas_equalTo(totalImage.mas_centerY);
    }];
    
    UIImageView * imageVin = [[UIImageView alloc]init];
    imageVin.image = [UIImage imageNamed:@"personal_arrow"];
    [totalImage addSubview:imageVin];
    [imageVin mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(totalImage.mas_right).with.offset(-10*kWidth);
        make.centerY.mas_equalTo(totalImage.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 11*kHeight));
    }];
    
    
    UIButton * btn = [UIButton createUIbutton:@"" andFont:FontOfSize13 andColor:nil];
    [btn addTarget:self action:@selector(pressCarVin) forControlEvents:UIControlEventTouchUpInside];
    [totalImage addSubview:btn];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(totalImage.mas_right);
        make.centerY.mas_equalTo(totalImage.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(Main_Width-20*kWidth, 40*kHeight));
    }];

    

    

    
    
    

    TimeImage = [[UIImageView alloc]init];
    TimeImage.image = [UIImage imageNamed:@"pickcar"];
    
    [_backview1 addSubview:TimeImage];
    [TimeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left).with.offset(22*kWidth);
        make.centerY.mas_equalTo(_TableView.mas_bottom).with.offset(60*kHeight);
        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
    }];
    
    //提车时间
    UILabel * TimeLabel = [UILabel createUIlabel:@"提车信息" andFont:14 andColor:UIlabelColor];
    [_backview1 addSubview:TimeLabel];
    [TimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(TimeImage.mas_centerY);
    }];
    
    [postDic setObject:@"0" forKey:@"isPick"];
    chooseTimeLabel = [UILabel createUIlabel:@"物流点发车" andFont:14 andColor:UIbtnColor];
    [_backview1 addSubview:chooseTimeLabel];
    [chooseTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(TimeLabel.mas_centerY).with.offset(30*kHeight);
    }];
    
    

    
    
    UIImageView * chooseImage3 = [[UIImageView alloc]init];
    chooseImage3.image = [UIImage imageNamed:@"personal_arrow"];
    
    [_backview1 addSubview:chooseImage3];
    [chooseImage3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-10*kWidth);
        make.centerY.mas_equalTo(chooseTimeLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 11*kHeight));
    }];
    
    
    
    
    UIButton * pressTimeBtn = [UIButton createUIbutton:@"" andFont:1 andColor:nil];
    [pressTimeBtn addTarget:self action:@selector(pressPickInforBtn) forControlEvents:UIControlEventTouchUpInside];
    [_backview1 addSubview:pressTimeBtn];
    [pressTimeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(chooseTimeLabel.mas_left);
        make.centerY.mas_equalTo(chooseTimeLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(Main_Width-20*kWidth, 40*kHeight));
    }];
    
    
    UIView * lineView3= [[UIView alloc]init];
    lineView3.backgroundColor = LineColor;
    [_backview1 addSubview:lineView3];
    [lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(chooseTimeLabel.mas_left);
        make.right.mas_equalTo(_backview1.mas_right);
        make.centerY.mas_equalTo(chooseTimeLabel.mas_centerY).with.offset(15*kHeight);
        make.height.mas_equalTo(0.5*kHeight);
    }];
    
    
    
    
    
    
    UIImageView * HandImage = [[UIImageView alloc]init];
    HandImage.image = [UIImage imageNamed:@"handcar"];
    
    [_backview1 addSubview:HandImage];
    [HandImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left).with.offset(22*kWidth);
        make.centerY.mas_equalTo(lineView3.mas_bottom).with.offset(30*kHeight);
        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
    }];
    
    //交车时间
    UILabel * HandTimeLabel = [UILabel createUIlabel:@"交车信息" andFont:14 andColor:UIlabelColor];
    [_backview1 addSubview:HandTimeLabel];
    [HandTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(HandImage.mas_centerY);
    }];
    
    [postDic setObject:@"0" forKey:@"isDeliv"];
    
    
    NSDate *date = [NSDate date]; // 获得时间对象
    NSDateFormatter  *dateformatterTime=[[NSDateFormatter alloc] init];
    [dateformatterTime setDateFormat:@"HH:mm:ss"];
    NSString * string = [dateformatterTime stringFromDate:date];
    NSString *  b = [string substringWithRange:NSMakeRange(0,2)] ;
    NSString *  c = [string substringWithRange:NSMakeRange(2,3)] ;
    
    
    NSString * btnlabel = [NSString stringWithFormat:@"%@%@",b,c];
    [postDic setObject:btnlabel forKey:@"pickTime"];
    
    
    
    NSDate *  senddate=[NSDate date];
    NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
    [dateformatter setDateFormat:@"YYYY-MM-dd"];
    NSString *  locationString=[dateformatter stringFromDate:senddate];
    [postDic setObject:locationString forKey:@"pickDate"];

    
    
    chooseHandTimeLabel = [UILabel createUIlabel:@"物流点自提" andFont:14 andColor:UIbtnColor];
    [_backview1 addSubview:chooseHandTimeLabel];
    [chooseHandTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(HandTimeLabel.mas_centerY).with.offset(30*kHeight);
    }];
    
    
    UIImageView * chooseHandImage3 = [[UIImageView alloc]init];
    chooseHandImage3.image = [UIImage imageNamed:@"personal_arrow"];
    
    [_backview1 addSubview:chooseHandImage3];
    [chooseHandImage3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-10*kWidth);
        make.centerY.mas_equalTo(chooseHandTimeLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 11*kHeight));
    }];

    
    
    
    
    UIButton * pressHandTimeBtn = [UIButton createUIbutton:@"" andFont:1 andColor:nil];
    [pressHandTimeBtn addTarget:self action:@selector(pressHandBtn) forControlEvents:UIControlEventTouchUpInside];
    [_backview1 addSubview:pressHandTimeBtn];
    [pressHandTimeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(chooseHandTimeLabel.mas_left);
        make.centerY.mas_equalTo(chooseHandTimeLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(Main_Width-20*kWidth, 40*kHeight));
    }];
    
    
    UIView * lineHandView4= [[UIView alloc]init];
    lineHandView4.backgroundColor = LineColor;
    [_backview1 addSubview:lineHandView4];
    [lineHandView4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(chooseHandTimeLabel.mas_left);
        make.right.mas_equalTo(_backview1.mas_right);
        make.centerY.mas_equalTo(chooseHandTimeLabel.mas_centerY).with.offset(15*kHeight);
        make.height.mas_equalTo(0.5*kHeight);
    }];

    
    
    UIImageView * StypeImage = [[UIImageView alloc]init];
    StypeImage.image = [UIImage imageNamed:@"type"];
    
    [_backview1 addSubview:StypeImage];
    [StypeImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left).with.offset(22*kWidth);
        make.centerY.mas_equalTo(lineHandView4.mas_bottom).with.offset(30*kHeight);
        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
    }];
    
    //交车时间
    UILabel * StypeLabel = [UILabel createUIlabel:@"运输方式" andFont:14 andColor:UIlabelColor];
    [_backview1 addSubview:StypeLabel];
    [StypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(StypeImage.mas_centerY);
    }];
    
    [postDic setObject:@"10" forKey:@"transportType"];
    
    UIButton * smallCar = [self createBtn:@"救援车" andBorderColor:LineGrayColor andFont:FontOfSize11 andTitleColor:littleBlackColor andBackColor:WhiteColor];
    smallCar.tag = SmallTag;
    [smallCar addTarget:self action:@selector(pressBigOrSmall:) forControlEvents:UIControlEventTouchUpInside];
    [_backview1 addSubview:smallCar];
    [smallCar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-15*kWidth);
        make.centerY.mas_equalTo(StypeLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(52*kWidth, 23*kHeight));
    }];
    UIButton *  bigCar= [self createBtn:@"大板车" andBorderColor:YellowColor andFont:FontOfSize11 andTitleColor:YellowColor andBackColor:WhiteColor];
    [bigCar setTitleColor:YellowColor forState:UIControlStateNormal];
    [_backview1 addSubview:bigCar];
    bigCar.tag = BigTag;
    [bigCar addTarget:self action:@selector(pressBigOrSmall:) forControlEvents:UIControlEventTouchUpInside];
    [bigCar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(smallCar.mas_left).with.offset(-8*kWidth);
        make.centerY.mas_equalTo(smallCar.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(52*kWidth, 23*kHeight));
    }];

    
    UIView * lineView5= [[UIView alloc]init];
    lineView5.backgroundColor = LineColor;
    [_backview1 addSubview:lineView5];
    [lineView5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(chooseHandTimeLabel.mas_left);
        make.right.mas_equalTo(_backview1.mas_right);
        make.centerY.mas_equalTo(bigCar.mas_centerY).with.offset(15*kHeight);
        make.height.mas_equalTo(0.5*kHeight);
    }];
    
    
    
    
    UIImageView * BillImage = [[UIImageView alloc]init];
    BillImage.image = [UIImage imageNamed:@"fapiao"];
    
    [_backview1 addSubview:BillImage];
    [BillImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview1.mas_left).with.offset(22*kWidth);
        make.centerY.mas_equalTo(lineView5.mas_bottom).with.offset(30*kHeight);
        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
    }];
    
    //交车时间
    UILabel * BillLabel = [UILabel createUIlabel:@"发票" andFont:14 andColor:UIlabelColor];
    [_backview1 addSubview:BillLabel];
    [BillLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(BillImage.mas_centerY);
    }];
    
    
    
    [postDic setObject:@"0" forKey:@"isTicket"];
    [postDic setObject:@"" forKey:@"companyName"];
    
    chooseBillLabel = [UILabel createUIlabel:@"不开票" andFont:14 andColor:UIbtnColor];
    [_backview1 addSubview:chooseBillLabel];
    [chooseBillLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addressLabel.mas_left);
        make.centerY.mas_equalTo(BillLabel.mas_centerY).with.offset(30*kHeight);
    }];
    

    UIImageView * imageBill = [[UIImageView alloc]init];
    imageBill.image = [UIImage imageNamed:@"personal_arrow"];
    [_backview1 addSubview:imageBill];
    [imageBill mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right).with.offset(-10*kWidth);
        make.centerY.mas_equalTo(chooseBillLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(6*kWidth, 11*kHeight));
    }];

    
    UIButton * BillBtn = [UIButton createUIbutton:@"" andFont:FontOfSize13 andColor:nil];
    [BillBtn addTarget:self action:@selector(pressInvoiceVC) forControlEvents:UIControlEventTouchUpInside];
    [_backview1 addSubview:BillBtn];
    
    [BillBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(_backview1.mas_right);
        make.centerY.mas_equalTo(chooseBillLabel.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(Main_Width-20*kWidth, 43*kHeight));
    }];


}


//提车信息
-(void)pressPickInforBtn{
    
    
    PickCarVC * carInfor = [[PickCarVC alloc]init];
    
    
    [carInfor.dicSouce setObject:postDic[@"departContact"] forKey:@"departContact"];
    [carInfor.dicSouce setObject:postDic[@"departPhone"] forKey:@"departPhone"];
    [carInfor.dicSouce setObject:postDic[@"departAddr"] forKey:@"departAddr"];
    [carInfor.dicSouce setObject:postDic[@"isPick"] forKey:@"isPick"];
    [carInfor.dicSouce setObject:postDic[@"pickDate"] forKey:@"pickDate"];
    [carInfor.dicSouce setObject:postDic[@"pickTime"] forKey:@"pickTime"];

    
    
    
    
    carInfor.callBackPickCarInfor = ^(NSMutableDictionary *dic){
        
//        [dataDic setObject:textField.text forKey:@"destContact"];
//        [dataDic setObject:textField.text forKey:@"destPhone"];
//        [dataDic setObject:textField.text forKey:@"departAddr"];
//        [dataDic setObject:str forKey:@"pickTime"];
//        [dataDic setObject:string forKey:@"pickDate"];
//        [dataDic setObject:str forKey:@"pickTime"];

        [postDic setObject:dic[@"people"] forKey:@"departContact"];
        [postDic setObject:dic[@"phone"] forKey:@"departPhone"];
        
        [postDic setObject:dic[@"address"] forKey:@"departAddr"];
        [postDic setObject:dic[@"isPick"] forKey:@"isPick"];
        [postDic setObject:dic[@"pickDate"] forKey:@"pickDate"];
        [postDic setObject:dic[@"pickTime"] forKey:@"pickTime"];
        
        NSString * str = nil;
        if ([postDic[@"isPick"] isEqualToString:@"0"]) {
            
            str = @"物流点提车";
        }else{
            str = @"上门提车";
        }
        chooseTimeLabel.text = [NSString stringWithFormat:@"%@   %@ %@",str,postDic[@"pickDate"],postDic[@"pickTime"]];
        
    };
    
    [self.navigationController pushViewController:carInfor animated:YES];
    
    
}
//交车信息

-(void)pressHandBtn{
    
    
    
    HandCarVC * carInfor = [[HandCarVC alloc]init];
    [carInfor.dicSouce setObject:postDic[@"destContact"] forKey:@"destContact"];
    [carInfor.dicSouce setObject:postDic[@"destPhone"] forKey:@"destPhone"];
    [carInfor.dicSouce setObject:postDic[@"destAddr"] forKey:@"destAddr"];
    [carInfor.dicSouce setObject:postDic[@"isDeliv"] forKey:@"isDeliv"];
    
    
    
    
    carInfor.callBackPickCarInfor = ^(NSMutableDictionary * dic){
        
        
        [postDic setObject:dic[@"people"] forKey:@"destContact"];
        [postDic setObject:dic[@"phone"] forKey:@"destPhone"];
        [postDic setObject:dic[@"address"] forKey:@"destAddr"];
        [postDic setObject:dic[@"isDeliv"] forKey:@"isDeliv"];

        
        NSString * str = nil;
        if ([postDic[@"isDeliv"] isEqualToString:@"0"]) {
            
            str = @"物流点自提";
        }else{
            str = @"送车上门";
        }
        chooseHandTimeLabel.text = [NSString stringWithFormat:@"%@",str];
      
        
        
    };
    [self.navigationController pushViewController:carInfor animated:YES];
    
}

//发票信息
-(void)pressInvoiceVC{
    
//    [dataDic setObject:@"0" forKey:@"isTicket"];
//    [dataDic setObject:@"" forKey:@"companyName"];
//    [dataDic setObject:@"" forKey:@"identifyNumber"];

    InvoiceVC * invoice = [[InvoiceVC alloc]init];
    
    [invoice.dicSouce setObject:postDic[@"isTicket"] forKey:@"isTicket"];
    [invoice.dicSouce setObject:postDic[@"companyName"] forKey:@"companyName"];
    [invoice.dicSouce setObject:postDic[@"identifyNumber"] forKey:@"identifyNumber"];

    
    invoice.callBackInvoice = ^(NSMutableDictionary * dic){
        
        [postDic setObject:dic[@"isTicket"] forKey:@"isTicket"];
        [postDic setObject:dic[@"companyName"] forKey:@"companyName"];
        [postDic setObject:dic[@"identifyNumber"] forKey:@"identifyNumber"];
        
        chooseBillLabel.text = [NSString stringWithFormat:@"开票   %@",dic[@"companyName"]];
        
    };
    [self.navigationController pushViewController:invoice animated:YES];
    
}


-(void)pressBigOrSmall:(UIButton*)sender{
    
    
    UIButton * big = (UIButton*)[self.view viewWithTag:BigTag];
    UIButton * small = (UIButton*)[self.view viewWithTag:SmallTag];
    if (sender.tag == BigTag) {
        big.layer.borderColor = YellowColor.CGColor;
        [big setTitleColor:YellowColor forState:UIControlStateNormal];
        small.layer.borderColor = LineGrayColor.CGColor;
        [small setTitleColor:littleBlackColor forState:UIControlStateNormal];
        [postDic setObject:@"10" forKey:@"transportType"];
    }else{
        small.layer.borderColor = YellowColor.CGColor;
        [small setTitleColor:YellowColor forState:UIControlStateNormal];
        big.layer.borderColor = LineGrayColor.CGColor;
        [big setTitleColor:littleBlackColor forState:UIControlStateNormal];
        [postDic setObject:@"20" forKey:@"transportType"];
    }

    
}


-(void)pressCarVin{
    
    
    NSLog(@"车架号");
    
    AddCarVinsVC * vinVc = [[AddCarVinsVC alloc]init];
    
    vinVc.carListArr = addCarInforArr;
    
    
    vinVc.callBackVin = ^(NSMutableArray * arr){
        
        addCarInforArr = arr;
        
    };
    
    
    
    [self.navigationController pushViewController:vinVc animated:YES];
    
}

#pragma mark - 创建背景图 二
-(void)createBackview2{
    
    _backview2 = [[UIView alloc]init];
    _backview2.backgroundColor = WhiteColor;
    [_ScrollView addSubview:_backview2];
    [_backview2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_ScrollView.mas_centerX);
        make.top.mas_equalTo(_backview1.mas_bottom).with.offset(10*kHeight);
        make.size.mas_equalTo(CGSizeMake(view_Width, 170*kHeight));
    }];
    
    //添加备注
    UIImageView * remarksImage = [[UIImageView alloc]init];
    remarksImage.image = [UIImage imageNamed:@"beizhu"];
    [_backview2 addSubview:remarksImage];
    [remarksImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(24*kWidth);
        make.top.mas_equalTo(_backview2.mas_top).with.offset(15*kHeight);
        make.size.mas_equalTo(CGSizeMake(14*kWidth, 14*kHeight));
    }];

    UILabel * remarksLabel = [UILabel createUIlabel:@"备注" andFont:14 andColor:UIlabelColor];
    [_backview2 addSubview:remarksLabel];
    [remarksLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(remarksImage.mas_right).with.offset(22*kWidth);
        make.centerY.mas_equalTo(remarksImage.mas_centerY);
    }];
    
    UITextView * field =[[UITextView alloc]init];
    field.frame = CGRectMake(14*kWidth, 64*kHeight, Main_Width-28*kWidth, 200*kWidth);
    field.tag = 1000;
    
    field.delegate = self;
    field.userInteractionEnabled = YES;
    field.text = @"添加商品车信息";
    field.backgroundColor = RGBACOLOR(248, 248, 248, 1);
    field.font = Font(FontOfSize14);
    field.textColor = UITextColor;
    field.backgroundColor = UITextBackColor;
    field.textAlignment = NSTextAlignmentLeft;
    field.returnKeyType = UIReturnKeyDone;
    [_backview2 addSubview:field];
    [field mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_backview2.mas_left).with.offset(24*kWidth);
        make.top.mas_equalTo(remarksLabel.mas_bottom).with.offset(18*kHeight);
        make.size.mas_equalTo(CGSizeMake(310*kWidth, 95*kHeight));
    }];
}


#pragma mark - 表单协议

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section{
    
    return addCarInforArr.count;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString  *CellIdentifier = @"CellIdentifier";
    
    AddCarCell * cell =  [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell ==nil) {
        cell = [[AddCarCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.SmallImage.contentMode = UIViewContentModeScaleAspectFit;//图片缩放适应imageView大小

//    {
//        amt = 1;
//        brandCode = asdmd;
//        brandId = 6;
//        brandLogoUrl = "http://qiniu.logo.huiyunche.cn/AstonMartin.png?e=1498205302&token=wQknukoe-lwcjLKEnsBz-BrL61M1BEMP0Gq_M2qP:TAZv1qRw0G2Pokcl_UT5RVnAVEI=";
//        brandName = "\U963f\U65af\U987f\U00b7\U9a6c\U4e01";
//        modelCode = "<null>";
//        modelId = 4732;
//        modelName = "V12 Vantage 2015\U6b3e 6.0L S";
//        seriesCode = V12Vantage;
//        seriesId = 69;
//        seriesName = "V12 Vantage";
//    },

    carModel = [CarInforModel ModelWithDic:addCarInforArr[indexPath.row]];
    
    [cell.SmallImage sd_setImageWithURL:[NSURL URLWithString:carModel.brandLogoUrl] placeholderImage:[UIImage imageNamed:@"car_1"]];
    NSString * carStr = [NSString stringWithFormat:@"%@-%@",carModel.brandName,carModel.seriesName];
    cell.SmallImage.contentMode = UIViewContentModeScaleAspectFit;//图片缩放适应imageView大小

    cell.CarName.text = carStr;
    NSString * carNumber = [NSString stringWithFormat:@"%@辆",carModel.amt];
    cell.CarNumber.text = carNumber;
    cell.deleteBtn.indexpath = indexPath;
    cell.addBtn.indexpath = indexPath;
    [cell.deleteBtn addTarget:self action:@selector(pressCarCellDeleteBtn:) forControlEvents:UIControlEventTouchUpInside];
    [cell.addBtn addTarget:self action:@selector(pressCarAddBtn:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
    
}



#pragma mark - 减少车型数量
-(void)pressCarCellDeleteBtn:(NewBtn*)sender{
    
    
    NSLog(@"%ld",(long)sender.indexpath.row);
    int numberCar = [addCarInforArr[sender.indexpath.row][@"amt"] intValue];
    numberCar  = numberCar - 1;
    
    
    
    if (numberCar == 0) {
        
        [addCarInforArr removeObjectAtIndex:sender.indexpath.row];
        [self updateBackFram:[addCarInforArr count]];

        addCarInforLabel.hidden = NO;
        
        [_TableView reloadData];
        
    }else{
        NSString * str = [NSString stringWithFormat:@"%d",numberCar];
        [addCarInforArr[sender.indexpath.row] setObject:str forKey:@"amt"];
        
        NSIndexPath *indexPath=[NSIndexPath indexPathForRow:sender.indexpath.row inSection:0];
        [_TableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
        totalImage.hidden = NO;
        


    }
    
    int sum = 0;
    NSMutableArray * arr = addCarInforArr.mutableCopy;
    
    for (int i = 0; i < arr.count; i++) {
        
        NSString * amt = [NSString stringWithFormat:@"%@",arr[i][@"amt"]];
        
        sum = sum + [amt intValue];
    }
    
    totalCarNumber.text = [NSString stringWithFormat:@"%d台",sum];

    
    if (addCarInforArr.count == 0) {
        
        [self updateBackFram:0];

        InforImage.hidden = YES;
        UIButton * btn = [_backview1 viewWithTag:10000];
        btn.userInteractionEnabled = NO;
        UIImageView * image1 = [_backview1 viewWithTag:100];;
        UIImageView * image2 = [_backview1 viewWithTag:200];
        image1.hidden = NO;
        image2.hidden = NO;
        _TableView.hidden = YES;
        totalImage.hidden = YES;

    }
}

#pragma mark - 增加车型数量
-(void)pressCarAddBtn:(NewBtn*)sender{
    
    NSLog(@"%ld",(long)sender.indexpath.row);
    int numberCar = [addCarInforArr[sender.indexpath.row][@"amt"] intValue];
    numberCar  = numberCar +1;
    NSLog(@"%d",numberCar);
    NSString * str = [NSString stringWithFormat:@"%d",numberCar];
    [addCarInforArr[sender.indexpath.row] setObject:str forKey:@"amt"];
    
    
    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:sender.indexpath.row inSection:0];
    [_TableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
    
    
    
    int sum = 0;
    
    NSMutableArray * arr = addCarInforArr.mutableCopy;
    
    for (int i = 0; i < arr.count; i++) {
        
        NSString * amt = [NSString stringWithFormat:@"%@",arr[i][@"amt"]];
        
        sum = sum + [amt intValue];
    }
    
    
    
    totalCarNumber.text = [NSString stringWithFormat:@"%d台",sum];
    

    
    
}


- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return  40*kHeight;
}



#pragma mark - 第一次增加车型
-(void)pressAddCarBtn{
    

    ChooseCarVC * addcar = [[ChooseCarVC alloc]init];
    addcar.callAddCar = ^(NSMutableDictionary * dic){
        
        NUmber ++;
        UIImageView * image1 = [_backview1 viewWithTag:100];;
        UIImageView * image2 = [_backview1 viewWithTag:200];
        image1.hidden = YES;
        image2.hidden = YES;
        addCarInforLabel.hidden = YES;
        InforImage.hidden = NO;
        UIButton * btn = [_backview1 viewWithTag:10000];
        btn.userInteractionEnabled = YES;
        
        [addCarInforArr addObject:dic];

        [self updateBackFram:[addCarInforArr count]];
        _TableView.hidden = NO;

        [_TableView reloadData];
        totalImage.hidden  =  NO;
        
        int sum = 0;
        
        NSMutableArray * arr = addCarInforArr.mutableCopy;
        
        for (int i = 0; i < arr.count; i++) {
            
            NSString * amt = [NSString stringWithFormat:@"%@",arr[i][@"amt"]];
            
            sum = sum + [amt intValue];
        }
        
        totalCarNumber.text = [NSString stringWithFormat:@"%d台",sum];
        
    };
    
    addcar.CarArr = addCarInforArr;
    
    [self.navigationController pushViewController:addcar animated:YES];
    
    
}

#pragma mark - 更改视图高度
-(void)updateBackFram:(long)number{
    
    
    
    if (addCarInforArr.count == 0) {
        
        totalImage.hidden = YES;
    }
    
    

    // 375
    _ScrollView.contentSize = CGSizeMake(Main_Width, Main_height+number*33+300*kHeight);
    [_backview1 mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo((550*kHeight+number*40*kHeight));
    }];
    
    [_TableView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(number*40*kHeight+10*kHeight);
    }];
    
    
    
    
//    [TimeImage mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.top.mas_equalTo(_TableView.mas_bottom).with.offset(10*kHeight);
//    }];


}

-(void)createBtn{
    
    UIButton * nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [nextBtn setTitle:@"下一步" forState:UIControlStateNormal];
    [nextBtn setTitleColor:WhiteColor forState:UIControlStateNormal];
    [nextBtn addTarget:self action:@selector(pressNextBtn:) forControlEvents:UIControlEventTouchUpInside];
    LRViewBorderRadius(nextBtn, 5, 0.5, YellowColor);
    nextBtn.backgroundColor = YellowColor;
    [_ScrollView addSubview:nextBtn];
    [nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(_ScrollView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(355*kWidth, 50*kHeight));
        make.top.mas_equalTo(_backview2.mas_bottom).with.offset(37*kHeight);
    }];
}

#pragma mark - 下一步
-(void)pressNextBtn:(UIButton*)sender{
    
    NSString * str = [NSString stringWithFormat:@"%ld",addCarInforArr.count];
    [postDic setObject:str forKey:@"brands"];
    
    long sum = 0;
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    for (int i = 0; i<addCarInforArr.count; i++) {
        
        int a = [addCarInforArr[i][@"amt"] intValue];
        sum = sum + a;
        
        NSString * str = [NSString stringWithFormat:@"%@",addCarInforArr[i][@"brandId"]];
        [dic setObject:str forKey:str];
        
    }


    NSUInteger count = dic.count;
    
    NSString * timeStr = [NSString stringWithFormat:@"%@",postDic[@"pickDate"]];
    
    NSString * endid = [NSString stringWithFormat:@"%@",endID];
    
    //判断信息填写是否完整
    if (count == 0) {
        [self createUIAlertController:@"请添加车型"];
    }else if (timeStr.length == 0 || [timeStr isEqualToString:@"(null)"] ){
        [self createUIAlertController:@"请选择提车时间"];
    }else if (endid.length == 0 || [endid isEqualToString:@"(null)"]){
        [self createUIAlertController:@"请选择目的地"];
    }else{
        
        NSString * sumStr = [NSString stringWithFormat:@"%lu",sum];
        //汽车总数量
        [postDic setObject:sumStr forKey:@"seriesAmt"];
        //车系总数量
        [postDic setObject:[NSString stringWithFormat:@"%lu",count] forKey:@"brands"];
        
        [postDic setObject:addCarInforArr forKey:@"orderSkuBOS"];
        
        NSString *urlString = [NSString stringWithFormat:@"%@/%@/%@/%@",Order_price,begainID,endID,sumStr];
        
        self.hud  = [WKProgressHUD showInView:self.view withText:@"" animated:YES];

        
        __weak typeof(self) weakSelf = self;
        
        [Common requestWithUrlString:urlString contentType:application_json finished:^(id responseObj) {
            
            NSLog(@"%@",responseObj[@"message"]);
            if ([responseObj[@"success"] boolValue]) {
                
               

                ConfirmVC * confirm = [[ConfirmVC alloc]init];
                confirm.handDic = postDic.mutableCopy;
                confirm.inforDic = responseObj[@"data"];
                
                //数据清空，重新下单
                confirm.callBack = ^(BOOL  yes){
                    
                    if (yes) {
                        
                        [weakSelf resetPostDic];
                        
                        [self updateBackFram:0];
                        endID= @"";
                        [addCarInforArr removeAllObjects];
                        begainAddressLabel.text = @"始发地";
                        begainAddressLabel.textColor = UIbtnColor;
                        endAddressLabel.text = @"目的地";
                        endAddressLabel.textColor = UIbtnColor;
                        
                        chooseTimeLabel.text = @"物流点发车";
//                        [postDic setObject:@"" forKey:@"departContact"];
//                        [postDic setObject:@"" forKey:@"departPhone"];
//                        [postDic setObject:@"" forKey:@"departAddr"];
//                        [postDic setObject:@"0" forKey:@"isPick"];
                        
                        NSDate *date = [NSDate date]; // 获得时间对象
                        NSDateFormatter  *dateformatterTime=[[NSDateFormatter alloc] init];
                        [dateformatterTime setDateFormat:@"HH:mm:ss"];
                        NSString * string = [dateformatterTime stringFromDate:date];
                        NSString *  b = [string substringWithRange:NSMakeRange(0,2)] ;
                        NSString *  c = [string substringWithRange:NSMakeRange(2,3)] ;
                        NSString * btnlabel = [NSString stringWithFormat:@"%@%@",b,c];
                        [postDic setObject:btnlabel forKey:@"pickTime"];
                        
                        
                        NSDate *  senddate=[NSDate date];
                        NSDateFormatter  *dateformatter=[[NSDateFormatter alloc] init];
                        [dateformatter setDateFormat:@"YYYY-MM-dd"];
                        NSString *  locationString=[dateformatter stringFromDate:senddate];
                        [postDic setObject:locationString forKey:@"pickDate"];

                        
                        chooseBillLabel.text = @"不开票";
                        [postDic setObject:@"0" forKey:@"isTicket"];
                        
                        chooseHandTimeLabel.text = @"物流点自提";
                        [postDic setObject:@"0" forKey:@"isDeliv"];
                        
                        
                        
                        chooseTimeLabel.textColor = UIbtnColor;
                        UITextView * textview = [_backview2 viewWithTag:1000];
                        textview.text = @"添加商品车信息";
                        textview.textColor = UITextColor;
                        
                        
                        //隐藏totalImage
                        totalImage.hidden = yes;
                        
//                        [postDic setObject:@"" forKey:@"comment"];

                        
                        //改为默认值 大板车
                        UIButton * big = (UIButton*)[self.view viewWithTag:BigTag];
                        UIButton * small = (UIButton*)[self.view viewWithTag:SmallTag];
                        big.layer.borderColor = YellowColor.CGColor;
                        [big setTitleColor:YellowColor forState:UIControlStateNormal];
                        small.layer.borderColor = LineGrayColor.CGColor;
                        [small setTitleColor:littleBlackColor forState:UIControlStateNormal];
                        [postDic setObject:@"10" forKey:@"transportType"];

                        [postDic setObject:@"" forKey:@"destRegionName"];
                        [postDic setObject:@"" forKey:@"destPhone"];
                        [postDic setObject:@"" forKey:@"destContact"];

                        
                        
                        UIImageView * image1 = [_backview1 viewWithTag:100];;
                        UIImageView * image2 = [_backview1 viewWithTag:200];
                        image1.hidden = NO;
                        image2.hidden = NO;
                        addCarInforLabel.hidden = NO;
                        _TableView.hidden = YES;
                        
                        [UIView animateWithDuration:0.3 animations:^{
                            /* 计算偏移量 */
                            
                            _ScrollView.contentOffset = CGPointMake(0, 0);
                            
                        } completion:nil];

                        
                    }
                };
                [self.navigationController pushViewController:confirm animated:YES];

            } else {
                [WKProgressHUD popMessage:responseObj[@"message"] inView:self.view duration:1.5 animated:YES];
            }
            [self.hud dismiss:YES];
            
        } failed:^(NSString *errorMsg) {
            
            [self.hud dismiss:YES];
            [WKProgressHUD popMessage:errorMsg inView:self.view duration:1.5 animated:YES];
            NSLog(@"%@",errorMsg);
            
        }];
    }
}


-(void)pressBegainBtn{
    
    

    BegainAddressChooseVC * address = [[BegainAddressChooseVC alloc]init];
    
//    @property (nonatomic,copy) void (^callBackAddress)(NSMutableDictionary * InforDic);

    address.callBackAddress = ^(NSMutableDictionary * inforDic){
        
        
        begainAddressLabel.text = [NSString stringWithFormat:@"%@",inforDic[@"sname"]];
        begainAddressLabel.textColor = AddCarColor;
        begainID = inforDic[@"id"];
//        [postDic setObject:dic[@"contact"] forKey:@"departContact"];
//        [postDic setObject:dic[@"phone"] forKey:@"departPhone"];

        
        //更改始发地时需要清空  目的地id 否则 运费查询失败
        NSString * end = [NSString stringWithFormat:@"%@",endID];
        [postDic setObject:inforDic[@"code"] forKey:@"departRegionCode"];
        [postDic setObject:inforDic[@"sname"] forKey:@"departRegionName"];

//        [postDic setObject:@"" forKey:@"departContact"];
//        [postDic setObject:@"" forKey:@"departPhone"];
        

        if (end.length >0) {
            endID = nil;
            [postDic setObject:@"" forKey:@"destRegionCode"];
            [postDic setObject:@"" forKey:@"destRegionName"];
            [postDic setObject:@"" forKey:@"departContact"];
            [postDic setObject:@"" forKey:@"departPhone"];
            endAddressLabel.text = @"目的地";
        }
    };
    
    
    [self.navigationController pushViewController:address animated:YES];
}

-(void)pressEndBtn{
    
    
    //选择始发地后，才能选择目的地
    NSString * address = [NSString stringWithFormat:@"%@",begainAddressLabel.text];
    if ([address isEqualToString:@"始发地"]) {
        
    
        [self createUIAlertController:@"请先选择始发地"];
    }else{
        
        
        EndAddressChooseVC *endaddress = [[EndAddressChooseVC alloc]init];
        endaddress.callBackAddress = ^(NSMutableDictionary * dic){
            
            endAddressLabel.text = [NSString stringWithFormat:@"%@",dic[@"sname"]];
            
            endAddressLabel.textColor = AddCarColor;
            endID = dic[@"id"];
            [postDic setObject:dic[@"code"] forKey:@"destRegionCode"];
            [postDic setObject:dic[@"sname"] forKey:@"destRegionName"];
            
        };
        
        
//        EndAddressVC * endaddress = [[EndAddressVC alloc]init];
//        endaddress.callBackInfor = ^(NSMutableDictionary * dic){
//            endAddressLabel.text = [NSString stringWithFormat:@"%@·%@·%@",dic[@"sname"],dic[@"contact"],dic[@"phone"]];
//
//            endAddressLabel.textColor = AddCarColor;
//            endID = dic[@"id"];
//            //    {
//            //        code = 440000;
//            //        id = 440000;
//            //        initialWords = gds;
//            //        level = province;
//            //        name = "\U5e7f\U4e1c\U7701";
//            //        parentCode = "<null>";
//            //        path = 440000;
//            //        pinyin = guangdongsheng;
//            //        sname = "\U5e7f\U4e1c\U7701";
//            //        status = 10;
//            //    },
//
//            [postDic setObject:dic[@"code"] forKey:@"destRegionCode"];
//            [postDic setObject:dic[@"sname"] forKey:@"destRegionName"];
//            [postDic setObject:dic[@"contact"] forKey:@"destContact"];
//            [postDic setObject:dic[@"phone"] forKey:@"destPhone"];
//        };
        
        endaddress.begainID = begainID;
        [self.navigationController pushViewController:endaddress animated:YES];
    }

}



#pragma mark UIPickerView

-(void)pressTimeBtn{
    
    UIDatePicker *datePicker = [[UIDatePicker alloc] init];
    ActionSheetPicker *actionSheet = [[ActionSheetPicker alloc] initWithTarget:self successAction:@selector(selectOK:) cancelAction:nil origin:datePicker];
    datePicker.datePickerMode=UIDatePickerModeDate;
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    //最小年月日（小于它，自动调回）
    NSDate* minDate = [NSDate date];
    //最大年月日（今天）
    NSDate* maxDate = [formatter dateFromString:@"2019-01-01"];
    datePicker.minimumDate = minDate;
    datePicker.maximumDate = maxDate;
    CGRect pickerFrame = CGRectMake(0, 40, actionSheet.viewSize.width, 216);
    [datePicker setFrame:pickerFrame];
    
    datePicker.datePickerMode = UIDatePickerModeDate;
    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];//设置为简体中文显示
    datePicker.locale = locale;
    actionSheet.pickerView = datePicker;
    actionSheet.title = @"";
    
    UIButton *leftBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [leftBtn setTitle:@"取消"forState:UIControlStateNormal];
    leftBtn.frame=CGRectMake(0, 0, 50, 45);
    [leftBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *leftIte=[[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    
    UIButton *rightBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    [rightBtn setTitle:@"完成" forState:UIControlStateNormal];
    rightBtn.frame=CGRectMake(0, 0, 50, 45);
    [rightBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    UIBarButtonItem *rightIte=[[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    [actionSheet setDoneButton:rightIte];
    [actionSheet setCancelButton:leftIte];
    [actionSheet showActionSheetPicker];
}
- (void)selectOK:(id)sender{
    if ([sender isKindOfClass:[UIDatePicker class]]) {
        
        UIDatePicker *picker = sender;
        NSDate * date = [picker date];
        
        //显示2015-07-23 的日期
        NSString *time = [[date description] substringWithRange:NSMakeRange(0, 10)];
        NSString *string = [NSString stringWithFormat:@"%@",time];

        
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        NSString *dateTime = [formatter stringFromDate:[NSDate date]];

        
        if ([Common compareDate:string withDate:dateTime]) {
            
            chooseTimeLabel.text = string;
            chooseTimeLabel.textColor = AddCarColor;
            [postDic setObject:string forKey:@"pickDate"];
        }else{
            chooseTimeLabel.text = dateTime;
            chooseTimeLabel.textColor = AddCarColor;
            [postDic setObject:dateTime forKey:@"pickDate"];
        }
    }
}


-(void)createUIAlertController:(NSString*)title
{
    UIAlertController * alert =[UIAlertController alertControllerWithTitle:@"提示" message:title preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction * action =[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        

    }];
    UIAlertAction * action1 =[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }];
    [alert addAction:action1];
    [alert addAction:action];
    [self presentViewController:alert animated:YES completion:nil];
}




-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
    //隐藏RootVC
    RootViewController *rootVC = [RootViewController defaultsTabBar];
    [rootVC setTabBarHidden:YES];

}



-(void)textViewDidChange:(UITextView *)textView{
    
    textView.textColor = littleBlackColor;
    [postDic setObject:textView.text forKey:@"comment"];
    NSInteger number = [textView.text length];
    if (number > 90) {
        number = 90;
        textView.text = [textView.text substringToIndex:number];
        [self createUIAlertController:@"留言限90字"];
    }
}




- (void)textViewDidEndEditing:(UITextView *)textView {
    
    if (textView.text.length == 0) {
        
        textView.text = @"添加商品车信息";
        textView.textColor = UITextColor;
    }
    [UIView animateWithDuration:0.2 animations:^{
        
        _ScrollView.contentOffset = CGPointMake(0, 0);
        
    }];

}


- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ( [ @"\n" isEqualToString: text])
    {
        
        [UIView animateWithDuration:0.3 animations:^{
            
            [textView resignFirstResponder];
            
        }];
        
        return  NO;
    }
    else
    {
        return YES;
    }
}

- (void)textViewDidBeginEditing:(UITextView *)textView {
    
    if ([textView.text isEqualToString:@"添加商品车信息"]) {
        textView.text = @"";
    }else{
        
    }
    [UIView animateWithDuration:0.5 animations:^{
        /* 计算偏移量 */
        
        _ScrollView.contentOffset = CGPointMake(0, 400+addCarInforArr.count*40);
        
    } completion:nil];

}

-(UIButton*)createBtn:(NSString*)title andBorderColor:(UIColor*)BorderColor andFont:(CGFloat)Font andTitleColor:(UIColor*)titleColor andBackColor:(UIColor*)BackColor {
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.layer.borderWidth = 0.5;
    btn.layer.cornerRadius = 5;
    btn.backgroundColor = BackColor;
    btn.layer.borderColor = BorderColor.CGColor;
    btn.titleLabel.font = Font(Font);
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setTitleColor:TitleColor forState:UIControlStateNormal];
    return btn;
}


@end
